//
//  DDTeamDescriptionCell.m
//  DingDongZP
//
//  Created by Jyh on 16/3/27.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDTeamDescriptionCell.h"
#import "SKTagView.h"

@interface DDTeamDescriptionCell ()

@property (strong, nonatomic) SKTagView *tagView;
@property (weak, nonatomic) IBOutlet UIView *lineView;

@end

@implementation DDTeamDescriptionCell

- (void)awakeFromNib {
    // Initialization code
//    self.detailView.layer.cornerRadius = 5;
//    self.detailView.layer.borderColor = COLOR_BORDER_GRAY.CGColor;
//    self.detailView.layer.borderWidth = 0.5;
    self.teamDescriptionLabel.text = @"";
}

- (void)updateTeamDescriptionCellWithInfo:(DDJobsDetail *)detailInfo
{
    WEAKSELF
    
    [self.detailView removeFromSuperview];
    [self.contentView addSubview:self.detailView];
    
    
    
    [self.detailView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(weakSelf.contentView.mas_top).offset(10);
        make.left.mas_equalTo(weakSelf.contentView.mas_left).offset(0);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).offset(0);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).offset(-1);
    }];
    
    [self.teamDescriptionLabel removeFromSuperview];
    [self.detailView addSubview:self.teamDescriptionLabel];
    
    CGFloat textWidth = kScreenWidth - (15*2);
    CGFloat textHeight = [DDUtils heightWithWidth:textWidth lineSpace:10 font:[UIFont systemFontOfSize:13] text:detailInfo.teamintro];
    //[DDUtils heightWithWidth:textWidth font:[UIFont systemFontOfSize:12.f] text:detailInfo.teamintro];

    
    NSMutableAttributedString *attr = [DDUtils attrWithString:10 font:[UIFont systemFontOfSize:13] text:detailInfo.teamintro];
    self.teamDescriptionLabel.attributedText = attr;
//    self.teamDescriptionLabel.text = detailInfo.teamintro;
    
    
    [self.teamDescriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
//        make.top.mas_equalTo(weakSelf.lineView.mas_bottom).offset(10);
        make.top.mas_equalTo(weakSelf.detailView.mas_top).offset(45);
        make.left.mas_equalTo(weakSelf.detailView.mas_left).offset(15);
//        make.right.mas_equalTo(weakSelf.detailView.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(textWidth, textHeight));
//        make.height.mas_equalTo(textHeight);
    }];

    if ([detailInfo.teamhighlights count] > 0) {
        [self addTagWithInfoWithArray:[detailInfo.teamhighlights mutableCopy]];
        
        [self.detailView addSubview:self.tagView];
        
        [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(weakSelf.detailView.mas_left).offset(1);
            make.top.mas_equalTo(weakSelf.teamDescriptionLabel.mas_bottom).offset(1);
            make.bottom.mas_equalTo(weakSelf.detailView.mas_bottom).offset(-1);
            make.right.mas_equalTo(weakSelf.detailView.mas_right).offset(-1);
        }];
    }
}

- (void)addTagWithInfoWithArray:(NSMutableArray *)tagArray
{
    //Add Tags
    if ([tagArray count] > 0) {
        [self.tagView removeAllSubviews];
        
        [tagArray enumerateObjectsUsingBlock:^(NSString *text, NSUInteger idx, BOOL * _Nonnull stop) {
            SKTag *tag = [SKTag tagWithText: text];
            tag.textColor = COLOR_FONT_LIGHT_GREEN;
            tag.fontSize = 12;
            tag.padding = UIEdgeInsetsMake(5, 5, 5, 5);
            tag.cornerRadius = 2;
            tag.borderWidth = 1;
            tag.borderColor = COLOR_FONT_LIGHT_GREEN;
            [self.tagView addTag:tag];
        }];
    }
}

- (SKTagView *)tagView {
    if (!_tagView) {
        _tagView = [SKTagView new];
        _tagView.backgroundColor = [UIColor whiteColor];
        _tagView.padding = UIEdgeInsetsMake(10, 10, 10, 10);
        _tagView.interitemSpacing = 10;
        _tagView.lineSpacing = 10;
    }
    
    return _tagView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
